package com.dss.auto_deploy.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.dss.auto_deploy.domain.*;
import com.dss.auto_deploy.dto.*;
import com.dss.auto_deploy.vo.AdmDockerDeployVo;
import com.dss.auto_deploy.vo.AllDockerInfoVo;
import com.github.dockerjava.api.DockerClient;

import java.io.IOException;
import java.util.List;

/**
* @Description:docker部署项目模块配置Service
* @author dongshoushan
* @date 2022-09-22 14:38:57
*/
public interface IAdmDockerDeployService  extends IService<AdmDockerDeploy> {
    /**
    * 新增docker部署项目模块配置
    * @param admDockerDeployAddDto
    * @return
    */
    Long insert(AdmDockerDeployAddDto admDockerDeployAddDto);

    /**
    * 修改docker部署项目模块配置
    * @param admDockerDeployUpdateDto
    * @return
    */
    int update(AdmDockerDeployUpdateDto admDockerDeployUpdateDto);

    /**
    * 批量删除docker部署项目模块配置
    * @param ids
    * @return
    */
    void deleteBatch(Long[] ids);

    /**
    * docker部署项目模块配置查询
    * @param dto
    * @return List<AdmDockerDeploy>
    */
    Page<AdmDockerDeployVo> list(AdmDockerDeployPageDto dto) throws InterruptedException;


    void alertSuccessMsg(String data);

    void alertFailMsg(String data);

    void reloadHtml();
    /**
     * docker部署上传
     * @param admDockerDeploy
     */
    void uploadService(AdmDockerDeploy admDockerDeploy) throws IOException;
    void bulidImage(AdmDockerDeploy dockerDeploy) throws Exception;
    void pushImageCmd(DockerClient dockerClient, String imageName, AdmDockerDeploy admDockerDeploy);
    /**
     * 拉取并启动新容器
     * @param admDockerDeploy
     * @param imageName
     */
    void pullAndStart(AdmDockerDeploy admDockerDeploy, String imageName);

    void versionUpdate(VersionUpdateDto dto) throws IOException;

    /**
     * 定时任务更新项目
     * @param projectId
     * @param namespaceId
     * @throws IOException
     */
    void jobToDeploy(Long projectId,Long namespaceId) throws IOException;

    List<AdmDockerDeployVo> getSuccess() throws InterruptedException;

    void restartService(String ids) throws IOException;

    void stopService(String ids);

    void pauseService(String ids);

    /**
     * 初始化清空
     */
    void init() throws IOException;

    List<AllDockerInfoVo> getAllDockerInfo(AllDockerInfoDto dto) throws InterruptedException;

    void updateTag(UpdateDockerTagDto updateDto);

    /**
     * maven编译
     * @param maven
     * @param list
     * @return
     */
    Boolean mavenBuild(String maven, List<AdmDockerDeploy> list);
    /**
     * 批量操作同一个项目模块
     * @param dto
     */
    void operation(OperationDto dto) throws InterruptedException;

    /**
     * 版本批量切换
     * @param dto
     */
    void changeTag(ChangeTagDto dto) throws IOException, InterruptedException;

    void addNode(AdmDockerDeployAddDto dto);

    void addModule(AdmDockerDeployAddDto dto);
    void delHstTag(String imageName, Long registryId);
    void delRegistry(Server server, AdmDockerRegistry admDockerRegistry, String imageName, String tag);

    /**
     * 存储到仓库
     *
     * @param tag
     * @param branch
     * @param admProject
     */
    void imageToRegistry(String tag, String branch, AdmProject admProject, List<AdmDockerDeploy> admDockerDeployList, AdmProjectAutoConfig autoConfig);

    void uploadImagesToProd(String tag, Long projectId, Long registryId, List<String> moduleNameList) throws Exception;

    void changeStatus(AdmDockerDeployUpdateDto updateDto);

    Boolean buildMaster(String maven) throws IOException;

    void restartServiceByIpAndServer(String ip, String module) throws IOException;
}
